package com.smh.a03converStreamDemo1;

import java.io.*;
import java.nio.charset.Charset;

public class ConvertStreamDemo3 {
    public static void main(String[] args) throws IOException {

        //文件格式转化
        FileReader fr = new FileReader("day27-code\\file\\demo1\\a.txt", Charset.forName("GBK"));
        FileWriter fw = new FileWriter("day27-code\\file\\demo1\\b.txt", Charset.forName("UTF-8"));

        char[] chars = new char[1024 * 1024];
        int len;
        while ((len = fr.read(chars)) != -1) {
            String s = new String(chars, 0, len);
            System.out.println(s);
            fw.write(s);
        }
        fw.close();
        fr.close();

        InputStreamReader isr = new InputStreamReader(new FileInputStream("day27-code\\file\\demo1\\a.txt"), "GBK");
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("day27-code\\file\\demo1\\b.txt"), "UTF-8");

        int ch;
        while ((ch = isr.read()) != -1) {
            osw.write(ch);
            System.out.print((char) ch);
        }
        osw.close();
        isr.close();

    }
}
